package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersPaymentDTO;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.entity.OrderDetail;
import com.sky.entity.Orders;
import com.sky.entity.ShoppingCart;
import com.sky.vo.DishVO;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import com.sky.vo.SalesTop10ReportVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {

    /**
     * 存入顶订单信息
     * @param orders
     */
    void submit(Orders orders);

    /**
     * 根据订单号查询订单信息
     * @param Number
     * @return
     */
    @Select("select id, number orderNumber,amount orderAmount,order_time orderTime from orders where number = #{Number}")
    OrderSubmitVO getByNumber(String Number);


    /**
     * 查询历史订单
     * @param ordersPageQueryDTO
     * @return
     */
    Page<OrderVO> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);
    //    Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);

    /**
     * 根据id查询订单
     * @param id
     * @return
     */
    @Select("select * from orders where id = #{id}")
    Orders getById(Long id);

    /**
     * 变更支付状态
     * @param orders
     */
    @Update("update orders set pay_status = #{payStatus} and id = #{id}")
    void payStatus(Orders orders);

    /**
     * 用于替换微信支付更新数据库状态的问题
     *
     * @param orderStatus
     * @param orderPaidStatus
     */

    @Update("update orders set status = #{orderStatus},pay_status = #{orderPaidStatus} ,checkout_time = #{check_out_time} where number = #{number}")
    void updateStatus(Integer orderStatus, Integer orderPaidStatus, LocalDateTime check_out_time, String number);

    /**
     * 变更订单状态
     * @param orders
     */
    void setStatus(Orders orders);

    /**
     * 各个状态的订单数量统计
     * @param status
     * @return
     */
//    @Select("select count(id) from orders where status = #{status}")
    Integer getStatistics(Integer status);

    @Select("select * from orders where status = #{status} and order_time < #{time}")
    List<Orders> getByStatusAndorderTimeLT(Integer status, LocalDateTime time);

    /**
     * 营业额统计
     * @param map
     * @return
     */
    Double sumByMap(Map map);

    /**
     * 获取当天订单数
     * @param map
     * @return
     */
    String getOrderCount(Map map);

    /**
     * 销量排行top10统计
     * @param map
     * @return
     */
    List<GoodsSalesDTO> getTop10(Map map);
}

